package com.homson.servicedomain.message.domain.converter;


import com.homson.coreservice.servicecommon.co.TransactionAddCO;
import com.homson.coreservice.servicecommon.enumeration.TransTypeEnum;
import com.homson.servicedomain.message.domain.model.TransactionAddedEvent;

import java.util.Objects;

/**
 * @author: homson_leo
 * @contact: hey_超级巨星（Homson_Leo）- 刘泓岑 1196816884@qq.com
 * @time: 2025/10/25 2:45 PM
 **/
public class TransactionEventConverter {
    
    public static TransactionAddedEvent convert(TransactionAddCO transactionAddCO){
        
        TransactionAddedEvent.TransactionAddedEventBuilder builder = TransactionAddedEvent.builder()
                .accountId(transactionAddCO.getAccountId())
                .amount(transactionAddCO.getAmount())
                .accountType(transactionAddCO.getAccountType())
                .transType(TransTypeEnum.of(transactionAddCO.getTransType()));
        
        if (Objects.nonNull(transactionAddCO.getTargetAccountId())) {
            builder.targetAccountId(transactionAddCO.getTargetAccountId());
        }
        if (Objects.nonNull(transactionAddCO.getTargetAccountType())) {
            builder.targetAccountType(transactionAddCO.getTargetAccountType());
        }
        return builder.build();
    }
    
}
